Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
thread.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 Roc authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_core/target_libuv/roc_core/thread.h
10//! @brief Thread.
11
12#ifndef ROC_CORE_THREAD_H_
13#define ROC_CORE_THREAD_H_
14
15#include <uv.h>
16
17#include "roc_core/atomic.h"
18#include "roc_core/mutex.h"
20
21namespace roc {
22namespace core {
23
24//! Base class for thread objects.
25class Thread : public NonCopyable<Thread> {
26public:
27 //! Check if thread was started and can be joined.
28 //! @returns
29 //! true if start() was called and join() was not called yet.
30 bool joinable() const;
31
32 //! Start thread.
33 //! @remarks
34 //! Executes run() in new thread.
35 bool start();
36
37 //! Join thread.
38 //! @remarks
39 //! Blocks until run() returns and thread terminates.
40 void join();
41
42protected:
43 virtual ~Thread();
44
45 Thread();
46
47 //! Method to be executed in thread.
48 virtual void run() = 0;
49
50private:
51 static void thread_runner_(void* ptr);
52
53 uv_thread_t thread_;
54
55 int started_;
56 Atomic joinable_;
57
58 Mutex mutex_;
59};
60
61} // namespace core
62} // namespace roc
63
64#endif // ROC_CORE_THREAD_H_
Atomic integer.
Atomic integer.
Definition: atomic.h:21
Mutex.
Definition: mutex.h:27
Base class for non-copyable objects.
Definition: noncopyable.h:23
Base class for thread objects.
Definition: thread.h:25
bool start()
Start thread.
void join()
Join thread.
virtual void run()=0
Method to be executed in thread.
bool joinable() const
Check if thread was started and can be joined.
Mutex.
Root namespace.
Non-copyable object.